﻿#include "rec_read_asf.h"
#include "cross_com.h"
#include "rec_data_io.h"
#include <stdint.h>
CRecReadASF::CRecReadASF(int clientID,int channel)
{
	m_curPos     = 0;
	m_pIdxBuf    = NULL;
	m_dataOffset = STFS_REC_DATA_OFFSET;
	m_pIdxBuf    = new STFS_REC_IDX[(STFS_REC_DATA_OFFSET - STFS_REC_IDX_OFFSET)/REC_INDEX_LEN];
	m_fileStatus = STFS_REC_WRITTING;

	m_playMode   = REPLAY_NORMAL;
	m_speed      = 1;
	m_stepIFrame = 1;
	m_version    = 0;
	m_fileLen    = 0;

	m_channel    = channel;
	m_clientID   =clientID;
	m_startTime	 = 0;
	m_endTime	 = 0;

	m_recOffset	 = 512;
	m_idxOffset  = 0;
	m_dataOffset = 0;
	m_fileIdx	 = -1;
	m_nBufSize   = SIZE_4MB;
	m_curTime    = 0;
	m_bDataEnd   = true;
	m_clientID   = 0;
	m_stepIFrame = 1;
	m_segIdx     = -1;
	m_fileIdx    =0 ;
	m_noReadCount = 0;
	m_bDownload    = false;
	m_fileStartLBA = 0;
	m_bLocalBackup = false;
	m_obj_inc.value = 0;
	m_data_pkt_size = SIZE_64KB;
	m_pkt_buf       = new uchar_t[m_data_pkt_size];
	m_frameNO       = 0;
	memset(&m_frmAddr,0,sizeof(FRAME_CRT_ADDR));

}

CRecReadASF::~CRecReadASF()
{
	if(m_pFile)
	{
		delete m_pFile;
	}
	if(m_pIdxBuf)
	{
		delete [] m_pIdxBuf;
	}

	if( 0 == m_clientID)
	{
		m_pFIFO = NULL;
	}
}

int CRecReadASF::Open(const char * dev, uint32_t fileIndex,int64_t startTime, int64_t endTime ,bool bClearBuf)
{
	int  ret = OpenSerialFile(dev,fileIndex);
	if(ret < 0)
	{
		TRACE("ch %d dev %s open fileindex %d.\n",m_channel,dev,fileIndex);
		return ret;
	}

	//读取STFS文件头信息
	ret = ReadRecInfo();
	if(ret < 0)
	{
		return ret;
	}

	ret = ReadASFHead();
	;
	m_obj_inc.value = 0;

	if( 0 != startTime )
	{
		SeekToTime(startTime,bClearBuf);
	}

	m_pFIFO->Open(m_channel,SIZE_MB(2));
	m_curPos = m_dataOffset;
	memset(&m_frmAddr,0,sizeof(FRAME_CRT_ADDR));
	StartDataIO();
	m_bDataEnd = false;

	return 0;
}

int CRecReadASF::ReadFrame(uchar_t* frameBuf, uint32_t bufLen)
{
	int ret = 0;
	uint32_t frameSize = 0;
	int wait_count = 500;
	uint32_t data_space = 0;
	//由底层，来智能读取缓冲数据
	for(int idx = 0 ; idx < 3; idx++)
	{
		frameSize = ret = m_pFIFO->GetFrame(frameBuf,bufLen);
		if(ret > 0)
		{
			break;
		}
		if(ERR_FIFO_NOTENOUGH == ret )
		{
			frameSize  = m_pFIFO->GetNextFrmSize();
			while(wait_count)
			{
				if(wait_count == 0)
				{
					TRACE("CH %02d Wait time too long.Free space %u \n",m_channel,data_space);
					PrintTimeMs(m_curTime,0,"last Frame Time");
					return FIFO_ERR_TIMEOUT;
				}

				CrossSleep(10);

				data_space = m_pFIFO->GetDataSize();
				if((data_space >= frameSize) && (frameSize != 0))
				{
					//TRACE_ERR("CH %02d FIFO_ERR_NOTENOUGH data_space %d data_size %d wait_count %d \n",m_channel,data_space,data_size,wait_count);
					break;
				}

				wait_count--;
			}

			if(wait_count == 0 && idx == 2)
			{
				TRACE_ERR("CH %02d Wait time too long.Free space %u\n",m_channel,data_space);
				m_bDataEnd = true;
				PrintTimeMs(m_curTime,0,"last Frame Time");
				return FIFO_ERR_TIMEOUT;
			}
		}
	}

	m_frmTool.Init(frameBuf);
	if(!m_frmTool.IsEffect())
	{
		LHN_FRAME_H * pFrm = (LHN_FRAME_H *) (frameBuf);

		m_bDataEnd = true;
		TRACE_ERR("ch%d FSFrameTag error  len%d  frame pts %lld!\n",
			       pFrm->dataLen,pFrm->channel,pFrm->pts);
		PrintTimeMs(pFrm->pts,0,"cur Frame Time");
		PrintTimeMs(m_curTime,0,"last Frame Time");
		CROSS_ASSERT(false);
		return 0;
	}

// 	if((m_curTime = m_frmTool.GetFrameTime()) >= m_endTime ||
//         m_curTime < m_startTime)//时间超过了录像段的结束时间
// 	{
// 		m_bDataEnd = true;
// 		TRACE_ERR("Time  Over file end. cur offset %d.\n",m_curPos);
// 		PrintTimeMs(m_frmTool.GetFrameTime(),0,"cur Time");
// 		PrintTimeMs(m_endTime,0,"last Frame Time");
// 		return 0;
// 	}
	//TRACE("Get on frame OK!",ret);e
	return ret;
}



int CRecReadASF::ReadASFHead()
{
	CROSS_ASSERT(NULL != m_headBuf);
	CROSS_ASSERT(NULL != m_pFile);

	//一次读取4K的数据,然后进行解析
	int ret = m_pFile->ReadPos(0,m_headBuf,HEAD_BUF_SIZE);
	if(ret < 0)
	{
		TRACE_ERR("CH %d index %d read head info fail ret %d.\n",
			       m_channel,m_fileIdx,ret);
		return ret;
	}
	uint32_t diffOff = 0;
	struct object_header_t * pObjheader = NULL;
	struct asf_header_object_t * pHead_obj = (struct asf_header_object_t *)(m_headBuf);
	if ( memcmp((uchar_t *)pHead_obj->objheader.guid, header_object_id, 16) != 0 )
	{
		fprintf(stderr, "CH %d index %d ----ASF File Header Object ID mismatch!\n",m_channel,m_fileIdx);
		ret = ERR_NOT_RECFILE;
		goto READ_ASF_FAIL;
	}
	//读取ASF文件头信息
	memcpy(&m_header_obj,pHead_obj,ASF_FILEHEAD_OBJ_LEN);
	diffOff += ASF_FILEHEAD_OBJ_LEN;

	for (uint32_t i = 0; i < m_header_obj.subobj_nums; i++)
	{
		if(diffOff >= HEAD_BUF_SIZE )
		{
			break;
		}

		pObjheader  =  (struct object_header_t *)(m_headBuf + diffOff);
		uint32_t objSize = (uint32_t)pObjheader->size;
		if (!m_obj_inc.have_file_propert && memcmp((uchar_t *)pObjheader->guid, file_properties_object_id, 16) == 0 )
		{
			memcpy(&m_fileprop_object,pObjheader,objSize);
			m_obj_inc.have_file_propert = 1;
			diffOff += objSize;
		}
		else if(!m_obj_inc.have_contern_obj&& memcmp((uchar_t *)pObjheader->guid, content_description_onject_id, 16) == 0 )
		{
			memcpy(&m_content_description_obj,pObjheader,objSize);
			m_obj_inc.have_contern_obj = 1;
			diffOff += objSize;
		}
		else if( (!m_obj_inc.have_video_stream_obj || !m_obj_inc.have_audio_stream_obj) &&
			   memcmp((uchar_t *)pObjheader->guid, stream_properties_object_id, 16) == 0 )
		{
			diffOff += 16;
			pObjheader  =  (struct object_header_t *)(m_headBuf + diffOff);
			if(!m_obj_inc.have_video_stream_obj &&  memcmp(pObjheader->guid, video_stream_object_id, 16) == 0 )
			{
				memcpy(&m_video_stream_properties_obj,pObjheader,objSize);
				m_obj_inc.have_video_stream_obj = 1;
			}
			else if(!m_obj_inc.have_audio_stream_obj &&  memcmp(pObjheader->guid, &m_audio_stream_properties_obj, 16) == 0)
			{
				memcpy(&m_audio_stream_properties_obj,pObjheader,objSize);
				m_obj_inc.have_audio_stream_obj = 1;
			}
			diffOff += objSize;
		}
		else if( !m_obj_inc.have_codec_lst_obj && memcmp((uchar_t *)pObjheader->guid, codec_list_object_id, 16) == 0 )
		{
			memcpy(&m_codec_list_obj,pObjheader,objSize);
			m_obj_inc.have_codec_lst_obj = 1;
			diffOff += objSize;
		}
		else if(!m_obj_inc.have_externsion_obj && memcmp((uchar_t *)pObjheader->guid, header_extension_object_id, 16) == 0)
		{
			memcpy(&m_header_extension_obj,pObjheader,objSize);
			m_obj_inc.have_externsion_obj = 1;
			diffOff += objSize;
		}
		diffOff++;
	}

	return 0;

READ_ASF_FAIL:
	return ret;
}
#ifndef INT64_C
#define INT64_C(c)	c ## LL
#endif // _INT64_C

int CRecReadASF::file_time_to_unix_time(uint64_t fftime)
{
	uint64_t tt;
	uint32_t tmpsecs;

	tt = fftime -  INT64_C(116444736000000000);   	// 1601/1/1的时间转换为1970/1/1开始的时间
	tmpsecs =(uint32_t)(tt / INT64_C(10000000));     			//得到秒数

	return tmpsecs;
}

void CRecReadASF::get_file_create_timestr(int32_t filetimet, char * timeBuf, int timeBufSz)
{
	time_t filetim_t;
	struct tm *fctm;
	if(timeBufSz < 30)
	{
		return;
	}
	filetim_t = filetimet;
	fctm = gmtime(&filetim_t);
	sprintf(timeBuf, "%d-%02d-%02d  %02d:%02d:%02d", 1900 + fctm->tm_year, fctm->tm_mon + 1, fctm->tm_mday,\
		fctm->tm_hour, fctm->tm_min, fctm->tm_sec < 60?fctm->tm_sec:59);

}

int CRecReadASF::show_file_properties_obj(struct asf_file_properties_object_t *tmpfilepropobj)
{
	int32_t fctime;
	char  fctime_str[40];
	struct asfvideo_time_t asfvideotime;

	//解读 file properties object的详细信息

	fprintf(stderr, "----FILE Properties Object information,Object size = %u bytes------\n", (uint32_t)tmpfilepropobj->objheader.size);
	fprintf(stderr, "Whole asf file size =  %u bytes\n", (uint32_t)tmpfilepropobj->file_size);

	fctime = file_time_to_unix_time(tmpfilepropobj->create_time);
	get_file_create_timestr(fctime, fctime_str,40);

	fprintf(stderr, "File Create time: %s\n", fctime_str);
	fprintf(stderr, "Total Data Packet counts = %u\n", (uint32_t)tmpfilepropobj->datapacket_counts);

	get_asfvideotime_from_fileprop(tmpfilepropobj->play_duration, &asfvideotime);

	fprintf(stderr, "Play Duration =  %02d:%02d:%02d.%d\n", asfvideotime.hour, asfvideotime.minute,
	asfvideotime.second, asfvideotime.msnums);

	get_asfvideotime_from_fileprop(tmpfilepropobj->send_duration, &asfvideotime);

	fprintf(stderr, "Send Duration =  %02d:%02d:%02d.%d\n", asfvideotime.hour, asfvideotime.minute,
	asfvideotime.second, asfvideotime.msnums);

	get_asfvideotime_from_fileprop(tmpfilepropobj->preroll*10000, &asfvideotime);

	fprintf(stderr, "Preroll =  %02d:%02d:%02d.%d\n", asfvideotime.hour, asfvideotime.minute,
	asfvideotime.second, asfvideotime.msnums);


	fprintf(stderr, "Min datapacket size = %u \n", (uint32_t)tmpfilepropobj->min_datapacket_size);
	fprintf(stderr, "Max datapacket size = %u \n", (uint32_t)tmpfilepropobj->max_datapacket_size);
	fprintf(stderr, "Max bitrate = %u  kbits/sec\n", (uint32_t)tmpfilepropobj->max_bitrate);
	fprintf(stderr, "------------------------------------------------------------------------\n\n");

	return 1;
}

int CRecReadASF::CreateFrame(uchar_t * dataBuf, uint32_t bufSize)
{
	int len = 0;

	return len;
}

int CRecReadASF::ReadFIFONormal()
{
	int ret = 0;
	uchar_t* pbuf = NULL;
	uint32_t   free_size  = m_pFIFO->GetFreeSize();

   //TRACE_CBS("Read To FIFO curoffset %d read_size %d.\n",m_curPos,read_size);
	uint32_t leaf_data = m_fileLen - m_curPos;// m_fileSize - m_cur_offset;
	if(0 == leaf_data )
    {
		m_bDataEnd = true;
		TRACE_ERR("Cur Pos %d fileLen %d   .\n",m_curPos,m_fileLen);
        return ERR_REPLAY_NODATA;
    }

	uint32_t bufSize  = 0;
	pbuf = GetReplayTmpBuf(bufSize);
	uint32_t readSize = 0;
	uint32_t readPos   = 0;

	if( 0 != m_frmAddr.dataPos)
	{
		TRACE_ERR("free_size %d  cacheSize %d \n",m_curPos,m_frmAddr.dataPos);
		free_size = free_size - m_frmAddr.dataPos ;
	}

	while( free_size  >= 2 * m_data_pkt_size)
	{
		readPos	= AlignToDataPacket(m_curPos);
		if(free_size > bufSize )
			readSize = bufSize;
		else
			readSize = SIZE_ROUND_ALIGN(free_size,m_data_pkt_size);//对齐对64KB

		ret = m_pFile->ReadPos(readPos,pbuf,readSize);
		if(ret < 0)
		{
			goto ERR_OUT;
		}

		ret = AnalyzeAsfToFIFO(pbuf,readSize);
		m_curPos  += readSize;
		//剩余空间计算必须实时更新
		free_size  = m_pFIFO->GetFreeSize();
	}

	return ret ;
ERR_OUT:
	TRACE_ERR("Read data fail.\n");
	return ret;
}

//带有校正偏移的函数
int CRecReadASF::ReadFIFOForward()	//只读取关键帧数据,具有跳帧处理
{
	int ret = 0;
	//	TRACE("CH%02d fileIndex %d ReadFIFOForward begin index %02d",m_channel,m_fileIdx,m_curIndex);
	unsigned char* pbuf = NULL;
	uint32_t readBufSize = m_pFIFO->GetFreeSize();
	uint32_t offset    = 0;
	uint32_t frmSize   = 0;
	uint32_t dataSize  = 0;
	uint32_t readSize  = 0;
	int		 frmCount  = 0;
	int		 nexIdx    = 0;
	uint32_t bufSize  = 0;
	pbuf = GetReplayTmpBuf(bufSize);
	CROSS_ASSERT(pbuf != NULL);
	m_pFile->Lock();
	uint32_t headLen  = BASE_FRAME_HEAD_LEN;
	uint32_t frmLen   = 0;
	while(dataSize + headLen < readBufSize )
	{
		nexIdx = m_curIndex + m_stepIFrame;
		if((nexIdx) >= m_maxIndex)
		{
			ret = ERR_REPLAY_BUFFULL;
			m_bDataEnd = true;
			break;
		}

		//增加时间结束判断 尽量不超录像段的时候
		if(m_pIdxBuf[nexIdx].tmMS > (m_endTime))
		{
			//	TRACE("CH%02d 1-2 Over buffer size.Last idx %d\n",m_channel,nexIdx);//Test Info
			ret = ERR_REPLAY_BUFFULL;
			m_bDataEnd = true;
			break;
		}

		offset = m_pIdxBuf[nexIdx].offset;
		frmSize= m_pIdxBuf[nexIdx].frameLen;

		if(frmSize & 0x01)  //进行偶数字节对齐写入到缓冲当中
		{
			frmSize += 1;
		}

		frmLen = frmSize+ headLen;
		if((dataSize + frmLen) > readBufSize )
		{
			break;
		}

		readSize = GetReadPacketSize(offset,frmSize);
		ret = m_pFile->ReadPos(offset,pbuf,readSize,false);
		if(ret < 0)
		{
			TRACE_ERR("CH%02d Read data error offset %d ,size %d. ret %d \n",m_channel,offset,frmSize, ret);
			goto ERR_REC;
		}

		//从DataPacket 中解析出I帧
		AnalyzeKeyFrame(pbuf,readSize,frmSize);
#if 0
		ret = m_pFIFO->write(( uchar_t* )pbuf,frmSize);
		if( ret < 0)
		{
			break;
		}
#endif
		m_curIndex += m_stepIFrame;
		dataSize   += frmLen;
		frmCount++;
	}

	m_curPos = offset;	//记录最后的Offset
	m_pFile->Unlock();
	return frmCount;

ERR_REC:
	m_pFile->Unlock();
	m_curPos = offset;
	m_bDataEnd = true;
	TRACE_ERR("Read data error . ret %d .\n",ret);
	return ret;
}

int CRecReadASF::ReadFIFOReback()	//逆向读取关键帧数
{
	int ret = 0;

	//TRACE("CH%02d fileIndex %d ReadFIFOForward begin index %02d",m_channel,m_fileIdx,m_curIndex);
	uchar_t* pbuf = NULL;
	uint32_t readBufSize = m_pFIFO->GetFreeSize();

	uint32_t offset    = 0;
	uint32_t frmSize   = 0;
	uint32_t dataSize  = 0;
	int		 frmCount  = 0;
	int		 nexIdx    = 0;
	uint32_t readSize  = 0;
	uint32_t bufSize   = 0;

	pbuf = GetReplayTmpBuf(bufSize);
	CROSS_ASSERT(pbuf != NULL);
	uint32_t headLen  = BASE_FRAME_HEAD_LEN;
	uint32_t frmLen   = 0;

	m_pFile->Lock();
	while(dataSize + headLen < readBufSize )
	{
		nexIdx = m_curIndex - m_stepIFrame;
		if((nexIdx) < 0)
		{
			ret = ERR_REPLAY_BUFFULL;
			m_bDataEnd = true;
			break;
		}

		//增加时间结束判断 尽量不超录像段的时候
		if(m_pIdxBuf[nexIdx].tmMS < m_startTime)
		{
			//	TRACE("CH%02d 1-2 Over buffer size.Last idx %d\n",m_channel,nexIdx);//Test Info
			ret = ERR_REPLAY_BUFFULL;
			m_bDataEnd = true;
			break;
		}

		offset  = m_pIdxBuf[nexIdx].offset;
		frmSize = m_pIdxBuf[nexIdx].frameLen;
		if(frmSize & 0x01)  //进行偶数字节对齐写入到缓冲当中
		{
			frmSize += 1;
		}
		if((dataSize + frmSize) > readBufSize )
		{
			break;
		}

		frmLen = frmSize+ headLen;
		//是否越界
		if((dataSize + frmLen) > readBufSize )
		{
			break;
		}

		readSize = GetReadPacketSize(offset,frmSize);
		ret = m_pFile->ReadPos(offset,pbuf,readSize,false);
		if(ret < 0)
		{
			TRACE_ERR("CH%02d Read data error offset %d ,size %d. ret %d \n",m_channel,offset,frmSize, ret);
			goto ERR_REC;
		}

		//从DataPacket 中解析出I帧
		PrintTimeSec(m_pIdxBuf[nexIdx].tmMS);
		AnalyzeKeyFrame(pbuf,readSize,frmSize);

		m_curIndex -= m_stepIFrame;
		dataSize   += frmSize;
		frmCount++;
	}

	m_curPos = offset;	//记录最后的Offset
	m_pFile->Unlock();
	return frmCount;

ERR_REC:
	m_pFile->Unlock();
	m_curPos   = offset;
	m_bDataEnd = true;
	TRACE_ERR("Read data error . ret %d .\n",ret);
	return ret;
}

int CRecReadASF::ReadFIFO2Forward()
{
	return  0;
}

void CRecReadASF::get_asfvideotime_from_fileprop(uint64_t fplaytime, struct asfvideo_time_t *asftime)
{
	int32_t tmpms, tmpsec, tmpmin, tmphour;

	asftime->hour = 0;
	asftime->minute = 0;
	asftime->second = 0;
	tmpms = (int32_t)(fplaytime/10000);   	//得到单位是ms的时间
	tmpsec = tmpms / 1000;    	// 得到 seconds
	tmpms = tmpms % 1000;     	// 得到 剩余的 ms
	tmpmin = tmpsec / 60;    	// 得到 分钟
	if ( tmpmin == 0 ) {
		asftime->second = tmpsec;
		asftime->msnums = tmpms;
	}
	else {
		tmpsec = tmpsec % 60;
		tmphour = tmpmin / 60;
		tmpmin = tmpmin % 60;
		asftime->hour = tmphour < 99?tmphour:99;
		asftime->minute = tmpmin;
		asftime->second = tmpsec;
		asftime->msnums = tmpms;
	}
	return;
}


int CRecReadASF::read_content_description_object(struct asf_content_description_object_t *pContentdescriptionobj,bool debugflag)
{
	char tmpbuf[200];
	char contentbuf[1000] = {0};
	uint32_t i, j, tmppos;

	//fread((char *)&(tmpcontentdescriptionobj->title_len), 10, 1, fp);
//	fread((char *)contentbuf, (uint32_t)(tmpcontentdescriptionobj->objheader.size - 34), 1, fp);
	memcpy(contentbuf,(uchar_t* )pContentdescriptionobj + 34,pContentdescriptionobj->title_len);
	//解读 content description object 的详细信息
	//注意Title,Author，copyright,Description等为双字节字符串,在Linux下我们只认ASCII
	if ( debugflag )
	{
		fprintf(stderr, "---------Content Description object,  Object size = %u bytes-----\n", (uint32_t)pContentdescriptionobj->objheader.size);
	}
	tmppos = 0;
	for ( i = tmppos, j = 0; i < pContentdescriptionobj->title_len; j++, i += 2) {
		tmpbuf[j] = contentbuf[i];
	}
	tmpbuf[j] = 0x00;
	tmppos += pContentdescriptionobj->title_len;
	if ( debugflag ) {
		fprintf(stderr, "Title: %s\n", tmpbuf);
	}
	for ( i = tmppos, j = 0; i < (pContentdescriptionobj->author_len + tmppos); j++, i += 2) {
		tmpbuf[j] = contentbuf[i];
	}
	tmpbuf[j] = 0x00;
	tmppos += pContentdescriptionobj->author_len;
	if ( debugflag ) {
		fprintf(stderr, "Author: %s\n", tmpbuf);
	}
	for ( i = tmppos, j = 0; i < (pContentdescriptionobj->copyright_len + tmppos); j++, i += 2) {
		tmpbuf[j] = contentbuf[i];
	}
	tmpbuf[j] = 0x00;
	tmppos += pContentdescriptionobj->copyright_len;
	if ( debugflag ) {
		fprintf(stderr, "Copyright: %s\n", tmpbuf);
		fprintf(stderr, "--------------------------------------------\n\n");
	}
	return 1;
}

//一个测试读取ASF的处理过程,逐步分析其各个部分并解析出H264帧和G726帧
//把全部帧读取到hisiplaypara.frame_largebuf申请的大内存中
//如果判断到 histplay.readasf_run = 0,则退出该读ASF文件的函数
//------------------------------------------------------------------
int CRecReadASF::read_data_object_to_largebuf()
{
    return 0;
}

uint32_t  CRecReadASF::GetReadPacketSize(uint32_t offset,uint32_t frmSize)
{
	uint32_t readSize = SIZE_ROUND_UP(frmSize + m_data_pkt_size ,m_data_pkt_size);
	if(offset +  readSize > m_fileLen )
	{
		readSize = m_fileLen - offset;
	}

	return readSize;
}

int   CRecReadASF::AnalyzeKeyFrame(uchar_t * frameBuf, uint32_t bufLen,uint32_t keyFrmSize)
{
	uint32_t totalpackets, curr_packet;
	uint32_t packet_size;
	uchar_t  *packetbuf = NULL;
//	struct error_correction_data_t tmp_errcorrdata;
	struct payload_parsing_information_t tmp_ppinfor;
	struct single_payload_t tmp_singlepayload;

	PayloadFlag_t tmp_payloadflag;
	uint32_t tmppos, tmp_payloadnums, tmp_payloadno;
	uint32_t curFrmLen = 0;
	uint32_t tmp_payloadsize;

	packet_size =  m_data_pkt_size;
	totalpackets = bufLen / packet_size;

	curFrmLen = 0;
	curr_packet    = (uint32_t)0;

	int       frmHeadLen = sizeof(LHN_FRAME_H);

	//获取缓冲的内存地址.
	m_pFIFO->GetFrmBuf(m_frmAddr,frmHeadLen,keyFrmSize);

	while ( curr_packet < totalpackets )
	{
		//逐步分析每一个DataPacket，从中按 Object 分离出每一个媒体对象
		packetbuf = (uchar_t *)(frameBuf + curr_packet * packet_size);		//得到 该DataPacket中的Error_correction_Data,一般为82 00 00
	//	memcpy((uchar_t *)&tmp_errcorrdata, packetbuf, 3);
		//得到该DataPacket中的Payload parsing information
		tmppos = 3;
		tmp_ppinfor.lentype_flag.value = packetbuf[tmppos++];
		tmp_ppinfor.property_flag.value = packetbuf[tmppos++];
		tmp_ppinfor.padding_length = (uint32_t)0;
		memcpy((uchar_t *)&tmp_ppinfor.padding_length, (uchar_t *)&packetbuf[tmppos], 2);
		tmppos += 2;
		memcpy((uchar_t *)&(tmp_ppinfor.send_time), (uchar_t *)&packetbuf[tmppos], 4);
		tmppos += 4;
		memcpy((uchar_t *)&(tmp_ppinfor.duration), (uchar_t *)&packetbuf[tmppos], 2);
		tmppos += 2;
		//如果本 DataPacket 中包含多个 Payloads，则读取下 payload flag
		if ( tmp_ppinfor.lentype_flag.multi_payloads_present == 1 )
		{
			tmp_payloadflag.value = packetbuf[tmppos++];
			tmp_payloadnums = tmp_payloadflag.numbers;
		}
		else
			tmp_payloadnums = 1;
		tmp_payloadno = 0;

		while ( tmp_payloadno < tmp_payloadnums )
		{
			// 根据 Payload nums 读取并分析每一个 Payload
			tmp_singlepayload.stream_number.value = packetbuf[tmppos++];
			tmp_singlepayload.media_object_number = packetbuf[tmppos++];
			memcpy((uchar_t *)&tmp_singlepayload.offset_mediaobj, (uchar_t *)&packetbuf[tmppos], 4);
			tmppos += 4;
			tmp_singlepayload.replicated_data_len = packetbuf[tmppos++];
			memcpy((uchar_t *)&tmp_singlepayload.mediaobject_size, (uchar_t *)&packetbuf[tmppos], 4);
			tmppos += 4;
			memcpy((uchar_t *)&tmp_singlepayload.present_time, (uchar_t *)&packetbuf[tmppos], 4);
			tmppos += 4;

			if ( 1 == tmp_payloadnums)
			{
				//本DataPacket中包含一个Payload
				//看看 Padding Length 是否 > 0
				tmp_payloadsize = packet_size - tmppos - tmp_ppinfor.padding_length;

				if(tmp_singlepayload.stream_number.key_frame)
				{
					CreateFrmData((packetbuf + tmppos),tmp_payloadsize);
					curFrmLen += tmp_payloadsize;
				}

				//如果是一帧,则把这个H264帧保存到文件中
				if ( curFrmLen >= keyFrmSize )
				{
					CROSS_ASSERT(curFrmLen == keyFrmSize);
					CreateFrameToFIFO(tmp_singlepayload);
					goto DETECT_OUT;
				}

				tmppos += tmp_payloadsize;
			}
			else
			{     //本DataPacket中包含多个Payloads
				//看看 PayloadFlag中 Payload Length 占几个字节
				tmp_payloadsize = (uint32_t)0;
				if ( tmp_payloadflag.length_type == 1 )
				{  //Payload Length is byte
					tmp_payloadsize = packetbuf[tmppos];
					tmppos += 1;
				}
				else if ( tmp_payloadflag.length_type == 2 )
				{  //Payload Length is word
					memcpy((uchar_t *)&tmp_payloadsize, (uchar_t *)&packetbuf[tmppos], 2);
					tmppos += 2;
				}
				else if ( tmp_payloadflag.length_type == 3 )
				{  //Payload Length is Dword
					memcpy((uchar_t *)&tmp_payloadsize, (uchar_t *)&packetbuf[tmppos], 4);
					tmppos += 4;
				}

				if(tmp_singlepayload.stream_number.key_frame)
				{
					CreateFrmData( (packetbuf + tmppos),tmp_payloadsize);
					curFrmLen += tmp_payloadsize;
				}

				if ( curFrmLen >= keyFrmSize )
				{
					CROSS_ASSERT(curFrmLen == keyFrmSize);
					CreateFrameToFIFO(tmp_singlepayload);
					curFrmLen = 0;
					goto DETECT_OUT;
				}

				tmppos += (uint16_t)tmp_payloadsize;
			}

			tmp_payloadno += 1;
		}
		curr_packet += 1;
	}
DETECT_OUT:

	return 0;
}
//对齐到data packet
uint32_t CRecReadASF::AlignToDataPacket(uint32_t srcOffset)
{
	CROSS_ASSERT(srcOffset >= m_dataOffset);

	uint32_t diffOffset = srcOffset - m_dataOffset;

	diffOffset = SIZE_ROUND_ALIGN(diffOffset,m_data_pkt_size);
	return  (diffOffset + m_dataOffset);
}

int CRecReadASF::AnalyzeAsfToFIFO(uchar_t * frameBuf, uint32_t bufLen,bool bSearchKey)
{
	uint32_t totalpackets, curr_packet;
	uint32_t packet_size;
	uchar_t *packetbuf = NULL;
	struct error_correction_data_t tmp_errcorrdata;
	struct payload_parsing_information_t tmp_ppinfor;
	struct single_payload_t tmp_singlepayload;

	PayloadFlag_t tmp_payloadflag;
	uint32_t tmppos, tmp_payloadnums, tmp_payloadno;
	uint32_t curFrmLen = 0;
	uint32_t tmp_payloadsize;

	packet_size =  m_data_pkt_size;
	totalpackets = bufLen / packet_size;

	int       frmHeadLen = sizeof(LHN_FRAME_H);
	uchar_t * frmBuf  = g_rec_dataIO.GetRpBuf(m_pFile->get_device_name());
	uchar_t * frmBody = frmBuf + frmHeadLen;
	uint32_t  frmPos = 0;

	CROSS_ASSERT(NULL != frmBuf);
	curr_packet  = (uint32_t)0;
	TRACE( "---------Start parse data object, split h264 frame  totalpackets  %d curr_packet %d,%d,------\n",totalpackets,curr_packet,totalpackets);

	while ( curr_packet < totalpackets )
	{
		//逐步分析每一个DataPacket，从中按 Object 分离出每一个媒体对象
		packetbuf = (uchar_t *)(frameBuf + curr_packet * packet_size);		//得到 该DataPacket中的Error_correction_Data,一般为82 00 00
		memcpy((uchar_t *)&tmp_errcorrdata, packetbuf, 3);
		//得到该DataPacket中的Payload parsing information
		tmppos = 3;
		tmp_ppinfor.lentype_flag.value = packetbuf[tmppos++];
		tmp_ppinfor.property_flag.value = packetbuf[tmppos++];
		tmp_ppinfor.padding_length = (uint32_t)0;
		memcpy((uchar_t *)&tmp_ppinfor.padding_length, (uchar_t *)&packetbuf[tmppos], 2);
		tmppos += 2;
		memcpy((uchar_t *)&(tmp_ppinfor.send_time), (uchar_t *)&packetbuf[tmppos], 4);
		tmppos += 4;
		memcpy((uchar_t *)&(tmp_ppinfor.duration), (uchar_t *)&packetbuf[tmppos], 2);
		tmppos += 2;
		//如果本 DataPacket 中包含多个 Payloads，则读取下 payload flag
		if ( tmp_ppinfor.lentype_flag.multi_payloads_present == 1 )
		{
			tmp_payloadflag.value = packetbuf[tmppos++];
			tmp_payloadnums = tmp_payloadflag.numbers;
		}
		else
			tmp_payloadnums = 1;
		tmp_payloadno = 0;

		while ( tmp_payloadno < tmp_payloadnums )
		{
			// 根据 Payload nums 读取并分析每一个 Payload
			tmp_singlepayload.stream_number.value = packetbuf[tmppos++];
			tmp_singlepayload.media_object_number = packetbuf[tmppos++];
			memcpy((uchar_t *)&tmp_singlepayload.offset_mediaobj, (uchar_t *)&packetbuf[tmppos], 4);
			tmppos += 4;
			tmp_singlepayload.replicated_data_len = packetbuf[tmppos++];
			memcpy((uchar_t *)&tmp_singlepayload.mediaobject_size, (uchar_t *)&packetbuf[tmppos], 4);
			tmppos += 4;
			memcpy((uchar_t *)&tmp_singlepayload.present_time, (uchar_t *)&packetbuf[tmppos], 4);
			tmppos += 4;

			if ( 1 == tmp_payloadnums)
			{
				//本DataPacket中包含一个Payload
				//看看 Padding Length 是否 > 0
				tmp_payloadsize = packet_size - tmppos - tmp_ppinfor.padding_length;
				//CreateFrmData( (packetbuf + tmppos),tmp_payloadsize);
				memcpy(frmBody + frmPos,packetbuf + tmppos,tmp_payloadsize);
				curFrmLen += tmp_payloadsize;
				//如果是一帧,则把这个H264帧保存到文件中
				if ( curFrmLen >= tmp_singlepayload.mediaobject_size )
				{
					//将 p_h264framebuf[...]，长度为 h264currframelen 的缓冲区保存如文件中
					//将H264帧和G726帧一块放入大缓冲区中
					curFrmLen = 0;
					CreateFrameToFIFO(tmp_singlepayload,frmBuf,curFrmLen);
				}
				tmppos += tmp_payloadsize;

			}
			else
			{     //本DataPacket中包含多个Payloads
				//看看 PayloadFlag中 Payload Length 占几个字节
				tmp_payloadsize = (uint32_t)0;
				if ( tmp_payloadflag.length_type == 1 )
				{  //Payload Length is byte
					tmp_payloadsize = packetbuf[tmppos];
					tmppos += 1;
				}
				else if ( tmp_payloadflag.length_type == 2 )
				{  //Payload Length is word
					memcpy((uchar_t *)&tmp_payloadsize, (uchar_t *)&packetbuf[tmppos], 2);
					tmppos += 2;
				}
				else if ( tmp_payloadflag.length_type == 3 )
				{  //Payload Length is Dword
					memcpy((uchar_t *)&tmp_payloadsize, (uchar_t *)&packetbuf[tmppos], 4);
					tmppos += 4;
				}
				curFrmLen +=  tmp_payloadsize;
				//CreateFrmData( (packetbuf + tmppos),tmp_payloadsize);
				memcpy(frmBody + frmPos,packetbuf + tmppos,tmp_payloadsize);
				//如果是一帧,则把这个H264帧保存到文件中
				if ( curFrmLen >= tmp_singlepayload.mediaobject_size )
				{
					CreateFrameToFIFO(tmp_singlepayload,frmBuf,curFrmLen);
					curFrmLen = 0;
				}
				tmppos += (uint16_t)tmp_payloadsize;
			}

			tmp_payloadno += 1;
		}
		curr_packet += 1;
	}
	return 0;
}

uint32_t CRecReadASF::CreateFrmData(uchar_t * frameBuf, int bufLen)
{
	int fragSize1 = 0;
	int fragSize2 = 0;


	if( m_frmAddr.dataPos  < m_frmAddr.bodySize )
	{
		if(m_frmAddr.dataPos + bufLen <= m_frmAddr.bodySize )
		{
			memcpy(m_frmAddr.pBody + m_frmAddr.dataPos,frameBuf,bufLen);
		}
		else
		{   // pBody [-----------|dataPos|----fragSize1----] pTail [-----fragSize2-------]
			//bufLen = fragSize1 + fragSize2; 数据被分段
			CROSS_ASSERT(m_frmAddr.pBody != NULL);
  			fragSize1 = m_frmAddr.bodySize - m_frmAddr.dataPos;
			memcpy(m_frmAddr.pBody + m_frmAddr.dataPos,frameBuf,fragSize1);

			CROSS_ASSERT(m_frmAddr.pTail != NULL);
			fragSize2 = bufLen - fragSize1;
			memcpy(m_frmAddr.pTail,frameBuf + fragSize1 ,fragSize2);
		}
	}
	else
	{    // pBody [----fragSize1----] pTail [---------|dataPos|----fragSize2-------]
		int diff = m_frmAddr.dataPos - m_frmAddr.bodySize;
		CROSS_ASSERT(m_frmAddr.pTail != NULL);
		memcpy(m_frmAddr.pTail + diff,frameBuf,bufLen);
	}

	m_frmAddr.dataPos += bufLen;
	return m_frmAddr.dataPos;
}

int CRecReadASF::CreateFrameToFIFO(struct single_payload_t & payload,uchar_t * frmBuf,uint32_t frmSize)
{
	uint32_t frameLen = m_frmAddr.frameSize  + sizeof(LHN_FRAME_H);
	LHN_FRAME_H * pHead = NULL;

	if(NULL == frmBuf)
	{
		pHead = (LHN_FRAME_H * )m_frmAddr.pHead;
	}
	else
	{
		pHead = (LHN_FRAME_H * )frmBuf;
	}

	uint32_t free_size = m_pFIFO->GetFreeSize();
	pHead->channel = m_channel;
	pHead->frameNo = m_frameNO++;
	pHead->dataLen = payload.mediaobject_size;
	pHead->frameTag =LHNFrameTag;
	if(payload.stream_number.number == VIDEO_STREAM_NUMBER )
	{
		if(payload.stream_number.key_frame)
			pHead->frameType = IFrame;
		else
			pHead->frameType = PFrame;
	}
	else
	{   //音频帧数据
		pHead->frameType = AFrame;
	}

	pHead->pts   = m_firstTime + payload.present_time ;

	if(m_frmAddr.bDeviHead)
	{   //头信息镜像技术
		uchar_t * pFragBuf =(uchar_t *)pHead + (BASE_FRAME_HEAD_LEN - m_frmAddr.fragmentSz);
		memcpy(m_frmAddr.pHeadFragment,pFragBuf,m_frmAddr.fragmentSz);
	}

	if(free_size <= frameLen)
	{
		TRACE("IFrame Create Data %d. free_size %d \n",frameLen,free_size);
		CROSS_ASSERT(free_size >= frameLen);
	}
	else
	{
		if(NULL == frmBuf)
		{
			m_pFIFO->ProductBuf(frameLen);
			if( IFrame ==pHead->frameType)
			{
#ifdef _WIN32
				PrintTimeMs(pHead->pts,0,"IFrame");
#endif
			}
		}
		else
		{
			m_pFIFO->PutFrame(frmBuf,frmSize);
		}
	}

	m_frmAddr.dataPos = 0;
	m_frmAddr.bStart  = false;

	return 0;
}
int CRecReadASF::read_codec_list_object(struct asf_codec_list_onject_t *tmpcodeclistobj, int debugflag)
{
#if 0
	char tmpbuf[1000];
	int tmppos, i, j;
	char namebuf[100];
	char descriptbuf[100];
	char inforbuf[100];

	struct codec_attr_t tmpcodecattr;
#endif
	/*
	//fread((char *)(tmpcodeclistobj->reserved_field), 20, 1, fp);
	//解读 codec list object 的详细信息
	if ( debugflag ) {
		if ( memcmp((char *)tmpcodeclistobj->reserved_field, asf_reserved_2_id, 16) != 0 ) {
			fprintf(stderr, "Codec list object, ASF_Reserved_2 is error!\n");
			return 0;
		}
	}
	fread((char *)tmpbuf, (uint32_t)(tmpcodeclistobj->objheader.size - 44), 1, fp);
	if ( debugflag ) {
		fprintf(stderr, "-------Codec list object, object size = %u bytes-----------\n", (uint32_t)tmpcodeclistobj->objheader.size);
		fprintf(stderr, "Codec nums = %u\n", tmpcodeclistobj->codec_nums);
	}
	tmppos = 0;
	if ( debugflag ) {
		fprintf(stderr, " Type                                                   Name                             Format\n");
	}
	memcpy((char *)&tmpcodecattr.type, tmpbuf, 4);
	tmppos += 4;
	if ( tmpcodecattr.type == 0x0001 ) {
		for ( i = 0, j = 0; i < tmpcodecattr.name_len*2; i += 2, j++) {
			namebuf[j] = tmpbuf[i+tmppos];
		}
		namebuf[j] = 0x00;
		tmppos += tmpcodecattr.name_len * 2;
		memcpy((char *)&tmpcodecattr.descript_len, (char *)&tmpbuf[tmppos], 2);
		tmppos += 2;
		for ( i = 0, j = 0; i < tmpcodecattr.descript_len*2; i += 2, j++) {
			descriptbuf[j] = tmpbuf[i+tmppos];
		}
		descriptbuf[j] = 0x00;
		tmppos += tmpcodecattr.descript_len*2;
		memcpy((char *)&tmpcodecattr.infor_len, (char *)&tmpbuf[tmppos], 2);
		tmppos += 2;
		for ( i = 0, j = 0; i < tmpcodecattr.infor_len; i++, j++) {
			inforbuf[j] = tmpbuf[i+tmppos];
		}
		inforbuf[j] = 0x00;
		tmppos += tmpcodecattr.infor_len;
		if ( debugflag ) {
			fprintf(stderr, "WMT_CODECINFO_VIDEO    %s                   %s\n", namebuf, inforbuf);
		}
	}
	else {
		fprintf(stderr, "-----Unknown codec type\n");
		return 0;
	}
	memcpy((char *)&tmpcodecattr.type, (char *)&tmpbuf[tmppos], 4);
	tmppos += 4;
	if ( tmpcodecattr.type == 0x0002 ) {
		for ( i = 0, j = 0; i < tmpcodecattr.name_len*2; i += 2, j++) {
			namebuf[j] = tmpbuf[i+tmppos];
		}
		namebuf[j] = 0x00;
		tmppos += tmpcodecattr.name_len * 2;
		memcpy((char *)&tmpcodecattr.descript_len, (char *)&tmpbuf[tmppos], 2);
		tmppos += 2;
		for ( i = 0, j = 0; i < tmpcodecattr.descript_len*2; i += 2,j++) {
			descriptbuf[j] = tmpbuf[i+tmppos];
		}
		descriptbuf[j] = 0x00;
		tmppos += tmpcodecattr.descript_len*2;
		memcpy((char *)&tmpcodecattr.infor_len, (char *)&tmpbuf[tmppos], 2);
		tmppos += 2;
		for ( i = 0, j = 0; i < tmpcodecattr.infor_len; i++, j++) {
			inforbuf[j] = tmpbuf[i+tmppos];
		}
		inforbuf[j] = 0x00;
		tmppos += tmpcodecattr.infor_len;
		ddd = inforbuf[1];
		ddd *= 256;
		ddd += inforbuf[0];
		if ( debugflag ) {
			fprintf(stderr, "WMT_CODECINFO_AUDIO   %s                   %d\n", namebuf, ddd);
		}
	}
	else  {
		fprintf(stderr, "Unknown codec type\n");
		return 0;
	}
	*/
	return 1;
}

int CRecReadASF::read_header_extension_object(struct asf_header_extension_object_t *tmpheaderextobj, int debugflag)
{
	//struct object_header_t objhead;
	/*
	fread((char *)(tmpheaderextobj->reserved_field1), 22, 1, fp);  	//读取headerextobject的其余部分
	fread((char *)&objhead, 24, 1, fp);  								//读入语言列表对象
	if ( memcmp((char *)objhead.guid, language_list_object_id, 16) == 0 ){
		fprintf(stderr, "++++++++ Language List Object ++++\r\n");
		tmp_languagelistobj.objheader = objhead;
		fread((char *)&tmp_languagelistobj.langnums, objhead.size - 24, 1, fp);
	}
	fread((char *)&tmp_paddingobj, 24, 1, fp);  //读入Padding Object
	if ( memcmp((char *)tmp_paddingobj.objheader.guid, padding_object_id, 16) == 0 ){
		//得到我们需要的PaddingObject区域
		if ( (tmp_paddingobj.objheader.size - 24) > 2000 ) {
			fread((char *)&hist_paddingbuf[0], tmp_paddingobj.objheader.size - 24, 1, fp);
		}
		else {
			//兼容老的ASF文件
			memset((char *)&hist_paddingbuf[0], 0, PADDING_MAX_GPS_SECS*sizeof(struct gps_asfsave_t));
		}
		fprintf(stderr, "++++++++ Padding Object: %d ++++\r\n", (int)(tmp_paddingobj.objheader.size - 24));
	}
	*/
	return 1;
}

int CRecReadASF::read_video_stream_properties_object(struct asf_video_stream_properties_object_t *tmpvideostreampropobj, int debugflag)
{
/*
	char comp_id[10];
	char tmpbuf[1000];
	int i;
	int tmp_video_codec_specified_buflen = 0;

//	fread((char *)&(tmpvideostreampropobj->err_correction_type_id), 38, 1, fp);
	if ( debugflag ) {
		// 解读 video stream properties object 的详细信息
		fprintf(stderr, "-------Stream Properties Object(Video), object size=%u------\n", (uint32_t)tmpvideostreampropobj->objheader.size);
		fprintf(stderr, "Type specified data length = %u\n", (uint32_t)tmpvideostreampropobj->type_specified_datalen);
		fprintf(stderr, "Err correction data length = %u\n", (uint32_t)tmpvideostreampropobj->err_correction_datalen);
	}
//	fread((char *)&(tmpvideostreampropobj->encoded_image_width), 40 + 11, 1, fp);
	tmp_video_codec_specified_buflen = tmpvideostreampropobj->format_datasize - 40;
	if ( tmp_video_codec_specified_buflen < 0 || tmp_video_codec_specified_buflen > 200 )
		tmp_video_codec_specified_buflen = 0;
//	fread((char *)tmp_video_codec_specified_buf, tmp_video_codec_specified_buflen, 1, fp);
	if ( debugflag ) {
		fprintf(stderr, "Stream Number: 0x%02x\n", tmpvideostreampropobj->flags&0x7f);
		fprintf(stderr, "Encoded image width = %u, image height = %u\n", tmpvideostreampropobj->encoded_image_width,
		tmpvideostreampropobj->encoded_image_height);
	}
	memcpy((char *)comp_id, (char *)&tmpvideostreampropobj->compress_id, 4);
	comp_id[4] = 0x00;
	if ( debugflag ) {
		fprintf(stderr, "Compress ID  is: %s\n", comp_id);
	}
	if ( debugflag ) {
		if ( tmp_video_codec_specified_buflen > 0 ) {
			fprintf(stderr, "Codec Specified Data Buf: ");
		//	for ( i = 0; i < tmp_video_codec_specified_buflen; i++)
		//		fprintf(stderr, "%02x,", tmp_video_codec_specified_buf[i]);
			fprintf(stderr, "\n");
		}
	}
	if ( tmpvideostreampropobj->err_correction_datalen > 0 ) {
//		fread((char *)tmpbuf, tmpvideostreampropobj->err_correction_datalen, 1, fp);
	}
	if ( debugflag ) {
		fprintf(stderr, "------------------------------------------------------\n\n");
	}
*/
	return 1;
}

int CRecReadASF::read_audio_stream_properties_object(struct asf_audio_stream_properties_object_t *tmpaudiostreampropobj, int debugflag)
{
//	fread((char *)&(tmpaudiostreampropobj->err_correction_type_id), 38, 1, fp);
	if ( debugflag ) {
		// 解读 Audio stream properties object 的详细信息
		fprintf(stderr, "-------Stream Properties Object(Audio), object size=%u------\n", (uint32_t)tmpaudiostreampropobj->objheader.size);
		fprintf(stderr, "Type specified data length = %u\n", (uint32_t)tmpaudiostreampropobj->type_specified_datalen);
		fprintf(stderr, "Err correction data length = %u\n", (uint32_t)tmpaudiostreampropobj->err_correction_datalen);
	}
	//fread((char *)&tmpaudiostreampropobj->format_tag, tmpaudiostreampropobj->type_specified_datalen, 1, fp);
	if ( debugflag )
	{
		fprintf(stderr, "Stream Number: 0x%02x\n", tmpaudiostreampropobj->flags&0x7f);
		fprintf(stderr, "Format tag is: %04x\n", tmpaudiostreampropobj->format_tag);
		fprintf(stderr, "audio channes is : %u\n", tmpaudiostreampropobj->channels);
		fprintf(stderr, "sample per second: %u\n", tmpaudiostreampropobj->sample_per_sec);
		fprintf(stderr, "bytes per seconds after encoded: %u bytes\n", tmpaudiostreampropobj->bytes_per_sec);
		fprintf(stderr, "bits per sample after encoded: %u bits\n", tmpaudiostreampropobj->bits_per_sample);
	}
	if ( tmpaudiostreampropobj->extra_datasize > 0 ) {
//		fread((char *)tmpbuf, tmpaudiostreampropobj->extra_datasize, 1, fp);
	}
	if ( tmpaudiostreampropobj->err_correction_datalen > 0 ) {
//		fread((char *)tmpbuf, tmpaudiostreampropobj->err_correction_datalen, 1, fp);
	}
	if ( debugflag ) {
		fprintf(stderr, "------------------------------------------------------\n\n");
	}
	return 1;
}




